﻿using System;
using System.Collections.Generic;

using BGM.Domain.DTO;


namespace BGM.Application.View
{
    public class PieDataPresenter:IDataPresenter
    {
        #region IDataPresenter Members

        public object GetPresentation(Patient patient, List<Reading> data)
        {
            return new PieUserControl( patient,GetPieSlices(data));
        }

        #endregion
        public Dictionary<string, double> GetPieSlices(List<Reading> data1)
        {
            Dictionary<string, double> data = new Dictionary<string, double>();
            if (data1.Count!=0)
            {
                int low = 0, ok = 0, high = 0, total = 0;
                foreach (var var in data1)
                {
                    total++;
                    if (ToMmolL(var.Value) >= 4 && ToMmolL(var.Value) <= 9)
                        ok++;
                    else if (ToMmolL(var.Value) < 4)
                        low++;
                    else if (ToMmolL(var.Value) > 9)
                        high++;
                }
                data.Add("Low", Math.Ceiling(((double)low / (double)total) * 100));
                data.Add("Ok", Math.Ceiling(((double)ok / (double)total) * 100));
                data.Add("High", Math.Ceiling(((double)high / (double)total) * 100));
            }
            return data;
        }
        private static double ToMmolL(double value)
        {
            return value / 18.00;
        }
        #region IPlugin Members

        public string Name
        {
            get { return "Pie data presenter"; }
        }

        public string Description
        {
            get { return "Pie presenter of mesurements"; }
        }

        #endregion

        #region IDisposable Members

        public void Dispose()
        {
            throw new NotImplementedException();
        }

        #endregion
    }
}
